import { ApiPrefixEnum } from '@/enums'
import { get, put } from '@/utils/http'

export interface SmsClientType {
  addr: string
  accessToken?: string
  dataPublicKey?: string
  appId: string
  appSecret: string
}

export interface SmsSubjectItemType {
  type: string
  label: string
  key: string
  value: string
  fieldType?: string
  required?: string
  placeholder?: string
  defaultValue?: string
  format?: string
  properties?: string
}

export interface SmsSubjectValueType {
  userRegisterCode: string
  userRegisterSucceedInform: string
  invitationInform: string
}

// 获取短信客户端配置
export function getUserCenterSmsClientPropertiesConfig() {
  return get<SmsClientType>(`${ApiPrefixEnum.CONTRACT}/aio/framework/optional/spring/properties/UserCenterSmsClientPropertiesConfig/data`)
}

// 更新短信客户端配置
export function updateUserCenterSmsClientPropertiesConfig(data: SmsClientType) {
  return put<any>(`${ApiPrefixEnum.CONTRACT}/aio/framework/optional/spring/properties/UserCenterSmsClientPropertiesConfig`, data)
}

// 获取短信主题表单
export function getUserCenterSmsTopicPropertiesConfig() {
  return get<{
    formName: string
    description: string
    alerts: string | null
    elements: SmsSubjectItemType[]
  }>(`${ApiPrefixEnum.CONTRACT}/aio/framework/optional/spring/properties/UserCenterSmsTopicPropertiesConfig/form/definition`)
}

// 获取短信主题表单
export function getUserCenterSmsTopicPropertiesConfigInitData() {
  return get<SmsSubjectValueType>(`${ApiPrefixEnum.CONTRACT}/aio/framework/optional/spring/properties/UserCenterSmsTopicPropertiesConfig/data`)
}

// 更新短信主题
export function updateUserCenterSmsTopicPropertiesConfig(data: SmsSubjectValueType) {
  return put<any>(`${ApiPrefixEnum.CONTRACT}/aio/framework/optional/spring/properties/UserCenterSmsTopicPropertiesConfig`, data)
}
